<div th:fragment="list" style="height: 100%;">
    <table id="dg" title="用户列表" style="width:100%;max-height:100%" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10">
        <thead data-options="frozen:true">
        <tr>
            <th field="name" width="80" align="center">姓名</th>
        </tr>
        </thead>
        <thead>
        <tr>
            <th field="mobile" width="100" align="center">手机</th>
            <th field="sex" width="80" formatter="sexIf" align="center">性别</th>
            <th field="age" width="80" align="center">年龄</th>
            <th field="birth" width="100" align="center">生日</th>
            <th field="dept" width="80" align="center">部门</th>
            <th field="office" width="80" align="center">科室</th>
            <th field="level" width="80" align="center">级别</th>
            <th field="isAdmin" width="80"formatter="isAdmin" align="center">系统身份</th>

        </tr>
        </thead>
    </table>
    <script>
        function getData(row, num) {
            if (row === null || row === undefined) {
                row = 1;
                num = 10;
                $('#dg').datagrid({loadFilter: pagerFilter});
            }
            $.ajax({
                url: "/list/user",
                type: "post",
                data: "row=" + row + "&num=" + num,
                dataType: "json",
                success: function (msg) {
                    if (msg.code === 200) {
                        $('#dg').datagrid('loadData', msg);
                    }
                }
            });
        }

        //分页
        function pagerFilter(msg) {
            let data = {
                total: msg.count,
                rows: msg.data
            }
            let dg = $(this);
            let pager = dg.datagrid('getPager');
            pager.pagination({
                onSelectPage: function (pageNum, pageSize) {
                    pager.pagination('refresh', {
                        pageNumber: pageNum,
                        pageSize: pageSize
                    });
                    getData(pageNum, pageSize);
                }
            });
            return data;
        }

        function sexIf(value) {
            return value === '1' ? '男' : '女';
        }

        function isAdmin(value) {
            return value === '1' ? '管理员' : '普通用户';
        }

        $(function () {
            getData();
        });
    </script>
</div>